package cn.the.angry;
import java.awt.Canvas;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

import cn.the.angry.login.LoginFrame;
import cn.the.angry.resourcemanager.ResourcePool;

/*
 * SplashScreen of the Angry Pigs
 */

public class SplashScreen extends JFrame{
	private static final int WIDTH = 1024;
	private static final int HEIGHT = 600;
		
	public SplashScreen(){
		super();
		this.setSize(new Dimension(WIDTH, HEIGHT));
		this.setTitle("Angry Pigs");
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setUndecorated(true);
		
		final BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
		final Graphics2D graphics2d=bi.createGraphics();
		//graphics2d.drawImage(b, 0, 0, SplashScreen.WIDTH, SplashScreen.HEIGHT, null);
		Canvas canvas = new Canvas(){
			@Override
			public void paint(Graphics g){
				g.drawImage(ResourcePool.getSplashScreen(), 0, 0, SplashScreen.WIDTH, SplashScreen.HEIGHT, null);
				g.dispose();
			}
		};
		Container contentPane = getContentPane();
		contentPane.add(canvas);
		
	}
	
	public static void main(String[] args){
		MainTest.loopMusic("/res/raw/title_theme.mp3", 1);
		final SplashScreen splashScreen =  new SplashScreen();
		splashScreen.setVisible(true);
		new Thread(){
			@Override
			public void run(){
				try {
					Thread.sleep(2000);
				} catch (Exception e) {
					e.printStackTrace();
				}
				new LoginFrame().setVisible(true);
				splashScreen.dispose();
			}
		}.start();
		
	}
}
